include io.asm

stack segment stack
	dw 128 dup (?)
stack ends

;;======================================================================
data segment
	Head db "Vasilenko Anatoly. Group 111.$"
	Input db "Enter please number: $"
	Output db "Answer: $"
	output1 db "not symmetric  $"
	answer db 19 dup(' '), '$'
data ends
;;======================================================================

code segment 'code'
	assume ss:stack, ds:data, cs:code
start:
	mov ax,data
	mov ds,ax
	lea dx, Head
	outstr
	newline
	newline
	;;------------------------------------------------------------------
		lea dx, Input;
		outstr;
		
		; Reading data with skiping blanks------------------------------
		xor ax, ax;
		xor dh, dh;
		mov cx, 16;
		L1:	inch dl;
			cmp dl, ' ';
			jne skip1;
			inch dl;
			
			skip1:
			sub dl, '0';
			shl ax, 1;
			or ax, dx;
		loop L1;
		
		; Data now is in 'ax'
		
		lea dx, Output;
		outstr;
		
		; Checking symmetry---------------------------------------------
		mov bx, ax;
		mov cx, 8;
		L2:	mov dl, 0;
			shl bl, 1;
			adc dl, 0;
			shr bh, 1;
			adc dl, 0;
			cmp dl, 1; if bh = 1 then it means that there is no symmetry
			je not_symmetric;			
		loop L2;
		
		; symmetric:----------------------------------------------------
		lea dx, output1[4];
		outstr;
		
		mov bl, al;
		mov cx, 8;
		L3:	shl bl, 1;
			jc break3;
		loop L3;
		break3:
		cmp cx, 0;
		je print;
		
		; 'cl' shows wrong byte now
		dec cl;
		; creating "mask" for 'ah'
		mov dl, 10000000b;
		shr dl, cl;
		xor ah, dl;
		; creating "mask" for 'al'
		mov dl, 1b;
		shl dl, cl;
		xor al, dl;
		je print;
		
		not_symmetric:;-------------------------------------------------
		lea dx, output1;
		outstr;
		
		mov dh, 0;
		shr ah, 1;
		adc dh, 0;
		shl al, 1;
		rcl ah, 1;
		shr dh, 1;
		rcr al, 1;
		
		; Answer:-------------------------------------------------------
		print:
		mov cx, 16;
		mov si, 18;
		L4: mov dl, 0;
			shr ax, 1;
			adc dl, '0';
			
			mov Answer[si], dl;
			dec si;
			
			dec si;
			cmp si, 13;
			je skip4;
			cmp si, 8;
			je skip4;
			cmp si, 3;
			je skip4;
			inc si;		
			skip4:
		loop L4;
		
		lea dx, Answer;
		outstr;
	;;------------------------------------------------------------------

the_end:
	newline;
	mov ah,8
	int 21h
    finish
code ends

;;======================================================================
end start 

;;======================================================================
